package com.example.csdn.service.impl;

import com.example.csdn.mapper.UserManageMapper;
import com.example.csdn.pojo.Article;
import com.example.csdn.pojo.PageBean;
import com.example.csdn.pojo.User;
import com.example.csdn.service.UserManageService;
import com.example.csdn.utils.Md5Util;
import com.example.csdn.utils.ThreadLocalUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserManageServiceImpl implements UserManageService {

    @Autowired
    private UserManageMapper userManageMapper;

    @Override
    public PageBean<User> userManageList(Integer pageNum, Integer pageSize, String identity) {
        //开启分页
        PageBean<User> pb = new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);

        List<User> list = userManageMapper.userManageList(identity);
        Page<User> page = (Page<User>) list;
        pb.setTotal(page.getTotal());
        pb.setItems(page.getResult());
        return pb;
    }

    @Override
    public void addUserManager(User user) {
        user.setPassword(Md5Util.getMD5String("123456"));
        user.setIdentity("普通用户");
        user.setStatus("启用");
        user.setUserDes("测试人员");
        userManageMapper.addUserManager(user);
    }

    @Override
    public void updateUserManager(User user) {
        userManageMapper.updateUserInfo(user);
    }

    @Override
    public void deleteUserManager(Integer id) {
        userManageMapper.deleteUserManager(id);
    }
}
